package com.example.zhongyuxin1011.xmlparser;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.TextView;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        TextView tv = (TextView) findViewById(R.id.tv);

        try {
            InputStream is = getResources().getAssets().open("users.xml");
            BufferedReader br = new BufferedReader(new InputStreamReader(is));
            String result = "";
            String tmp;
            while ((tmp = br.readLine()) != null) {
                result += tmp;
            }

//            tv.setText(result);
            Usrs usrs1 = XmlUtils.toBean(Usrs.class, result);
            if (usrs1 != null) {
                tv.setText(usrs1.toString());
            }

            br.close();
            is.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
